Repository navigation
Conversation
问题(#6):pathmap::is_full_oid 同时接受 40 与 64 位小写 hex,而 SHA-1 仓库上非实验构建的 git_oid_fromstr 恰好解析 40 个字符、无视余下 24 位 ——/commit/<64-hex> 被静默解析为其前 40 位前缀命中的 commit(实测命中 HEAD),违反 RFC 0000 §3.1"完整小写 oid,长度须与仓库对象格式一致"。 实现:resolve_locked 的 Ns::Commit 分支在 is_full_oid 之外叠加按 repo_->oid_type() 的长度校验(SHA-1=40 / 其他=64,三元式与 rawobj.cpp:29 既有惯例一致,不引入版本敏感的 git_oid_hexsize);长度 不符即 ENOENT。其余逻辑(tree 漫游、无 peeling、replace refs 不生效) 不动。附注:SHA-256 仓库本就无法挂载(git_repository_open 返回 "unknown object format"),64-hex 形态当前只能表现为本别名缺陷。 测试:tests/integration/run_tests.sh 追加三例——40-hex 真实 commit 目录可列举(回归)、64-hex(40-hex+24 个 0)oid 与深层路径均 ENOENT; 红/绿验证:无修复时新用例 2 FAIL(113 passed / 2 failed),加修复后 115 passed / 0 failed(本机 /dev/fuse + fusermount3 实跑)。 CHANGELOG:Unreleased/Fixed 记录。 Closes #6
|
This pull request has been automatically marked as stale because it has not had activity in 14 days. It will be closed in 7 days if no further activity occurs. |
|
Closed automatically due to inactivity. Feel free to reopen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6
问题
安全审查实测抓获:SHA-1 仓库上访问
/commit/<64位小写hex>/...,pathmap::is_full_oid(src/path_map.cpp:42)同时接受 40 与 64 hex 而放行,随后
git_oid_fromstr(src/gitmount.cpp:480)在非实验构建下固定解析恰好 40 个 hex 字符、不看余下 24 位——rc=0,得到该 64-hex 串
前 40 位前缀的 oid。若前缀恰为真实 commit(实测命中 HEAD),整棵树
被正常服务,违反 RFC 0000 §3.1:/commit 只接受与仓库对象格式一致的
完整小写 oid,其余应 ENOENT。定性为低危路径别名/规范松弛(前缀必须是
真实存在的 commit,无越权读写、无错误数据)。
实现
src/gitmount.cpp
resolve_locked的Ns::Commit分支:在is_full_oid校验处叠加按仓库对象格式的长度校验:三元式与 rawobj.cpp:29 既有惯例一致;不引入对 libgit2 版本敏感的
git_oid_hexsize。其余逻辑(tree 漫游、无 peeling、replace refs不生效)不动。
tests/integration/run_tests.sh:
/commit (§3.1)用例组追加三例,沿用脚本既有
check/test ! -e断言模式:$MAIN_TIP拼 24 个 0)oid → ENOENT;/commit/<64-hex>/src/hello.txt→ ENOENT。fixture 仓库无需新形态,
make_repo.sh未改;用例位于 main mount段内,天然受 /dev/fuse 缺失时的整段跳过保护。
CHANGELOG.md:顶部新增
## [Unreleased]/### Fixed英文条目。附注:SHA-256 仓库本就无法挂载(非实验 libgit2 的
git_repository_open对 sha256 仓库返回
unknown object format),64-hex 形态在当前构建下只能表现为本别名缺陷;rawobj 的
GIT_OID_SHA256分支作为正确的未来铺垫保留不动(见 #6 关联说明)。
测试证据(红/绿)
本机 /dev/fuse + fusermount3 可用,集成测试实跑:
FAIL - /commit rejects 64-hex oid (SHA-1 prefix alias)、FAIL - /commit rejects 64-hex deep path——旧代码确实命中前缀别名;passed: 113 / failed: 2ok,passed: 115 / failed: 0 / skipped: 1(仅 root 专属 mount(8) 段)100% tests passed out of 2(-DCMAKE_BUILD_TYPE=Debug -DGITMOUNT_WERROR=ON)改动文件已过 clang-format 18.1.8(项目锁定版本);bash 脚本与
CHANGELOG 不适用。单 commit,遵循 Conventional Commits。
风险
极低:新增的是更严格的前置拒绝(多拒一类本不该存在的地址形式),
不改变任何既有合法路径的解析结果;40-hex 全量集成用例与单测保持绿。
对 SHA-256 仓库(当前不可挂载)预留的 64 长度分支行为不变。
English summary
pathmap::is_full_oidaccepts both 40- and 64-hex strings, but thenon-experimental libgit2
git_oid_fromstrparses exactly 40 hex digitsand ignores the rest — on a SHA-1 repository a 64-hex
/commit/<oid>path silently resolved to the commit named by its 40-char prefix
(verified live against HEAD, issue #6). RFC 0000 §3.1 requires the full
oid to match the repository's object format; anything else must ENOENT.
Fix: in the
Ns::Commitbranch ofresolve_locked, validate thecomponent length against
repo_->oid_type()(40 for SHA-1, 64otherwise — same ternary convention as rawobj.cpp:29, avoiding the
version-sensitive
git_oid_hexsize) before parsing. Tree walking, nopeeling and replace-refs passthrough are untouched.
Tests: three new integration assertions in the
/commitgroup — a real40-hex commit dir still lists, while a 64-hex oid (real oid + 24 zeros)
and its deep path are ENOENT. Red/green: without the fix the two new
cases fail (113 passed / 2 failed); with it 115 passed / 0 failed
(skipped: 1, root-only mount(8) section). Unit + integration ctest
green under
-DGITMOUNT_WERROR=ON. No fixture changes needed; CHANGELOGUnreleased/Fixed entry added.
Closes #6